<?php
namespace app\payment\controller;

use tp5_lib\common\controller\TestBaseController;
use tp5_lib\account\logic\AccountLogic;
use app\payment\logic\PaymentLogic;

class TestController extends TestBaseController
{
    public function index()
    {
        return $this->fetch();
    }
    /**
     * 测试顾客端创建支付订单
     */
    public function pay()
    {
        $data=input();
        $logic=new PaymentLogic();
        $id=$logic->create($data["payer"], $data["payee"], $data["amount"]);

        $account=new AccountLogic();
        return $account->precreate($data["way"],"payment",$id,$data["amount"],"支付");
    }
    /**
     * 测试顾客端付款成功
     */
    public function doPay()
    {
        if(!$id=input("id")){
            $this->error("交易编号不能为空");
        }
        $logic=new PaymentLogic();
        if(!$logic->paySuccess($id)){
            $this->error("交易失败");
        }
        $this->success();
    }
    /**
     * 测试交易分成计算
     */
    public function royalty()
    {
        $data=input();
        $logic=new PaymentLogic();
        if(!$list=$logic->royalty($data["id"],$data["payer"],$data["payee"],$data["amount"])) $this->error($logic->getError());
        $this->result($list,1);
    }
}
